package com.zmks.jkgj.xuexiao.controller;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;


import com.zmks.jkgj.core.controller.ABaseController;
import com.zmks.jkgj.core.resp.Resp;
import com.zmks.jkgj.xuexiao.SessionManager;
import com.zmks.jkgj.xuexiao.resp.WebResp;
import com.zmks.jkgj.xuexiao.service.ICrctBusiScoreItemService;
import com.zmks.jkgj.xuexiao.service.ICrctObjSchoolService;
import com.zmks.jkgj.xuexiao.vo.CrctBusiScoreItemVO;
import com.zmks.jkgj.xuexiao.vo.CrctObjSchoolVO;

@Controller
public class CrctBusiScoreItemController extends ABaseController {
@Autowired
	
	private ICrctBusiScoreItemService crctBusiScoreItemService;	


	 //查询
	@RequestMapping("/get_CrctBusiScoreItem_list")
	@ResponseBody
	public Resp get_CrctBusiScoreItem_list( Integer pageIndex,
			Integer pageSize,HttpServletRequest request,String  sheet_sch_oid) {
		WebResp 	webResp = new WebResp();
	 
		 CrctBusiScoreItemVO crctBusiScoreItemVO=new  CrctBusiScoreItemVO();
//		 String  school_oid = SessionManager.getsession(request).getSchool_oid();
//		
		 crctBusiScoreItemVO.setSheet_sch_oid(Long.parseLong(sheet_sch_oid));
		 
		List<CrctBusiScoreItemVO> lista=crctBusiScoreItemService.getList(crctBusiScoreItemVO);
		HashMap map=new HashMap();
		  for(int i=0;i<lista.size();i++)
		{
			   String id=lista.get(i).getStudent_oid().toString();
			   String kemu=lista.get(i).getSubject().toString();
			   String  fenshu=lista.get(i).getScore_num().toString();
			  System.out.println( lista.get(i).getStudent_oid().toString());
			   if(map.get(id)==null)
			  {     HashMap mapdata=new HashMap();
			        mapdata.put("id", id);
			        mapdata.put(kemu, fenshu);
			        map.put(id, mapdata);
			  }else{
				  HashMap mapc=  (HashMap) map.get(id);
				  mapc.put(kemu, fenshu);
			  }
			
		}
		  List datalist=new   ArrayList();
		  Iterator it = map.entrySet().iterator();
		   while (it.hasNext()) {
		    Map.Entry entry = (Map.Entry) it.next();
		    Object key = entry.getKey();
		    System.out.println( "key"+key);
		    Object value = entry.getValue();
		    datalist.add(value);
		 
		   }
		
		
	    //学员成绩
		   HashMap mapdatamap=new HashMap();
		   mapdatamap.put("clo", crctBusiScoreItemService.getCoulmn(Long.parseLong(sheet_sch_oid)));
		   mapdatamap.put("data", datalist);
		   webResp.setData(mapdatamap);
		webResp.setTotalCount(15);
		return webResp;
	}
	 //查询
	@RequestMapping("/get_CrctBusiScoreItem_list_all")
	@ResponseBody
	public Resp get_CrctBusiScoreItem_list_all( Integer pageIndex,
			Integer pageSize,HttpServletRequest request) {
		WebResp 	webResp = new WebResp();
	   CrctBusiScoreItemVO crctBusiScoreItemVO=new  CrctBusiScoreItemVO();
		webResp.setData(crctBusiScoreItemService.getList(crctBusiScoreItemVO));
		webResp.setTotalCount(15);
		return webResp;
	}
	
	
	 //增加
	@RequestMapping("/save_CrctBusiScoreItem")
	@ResponseBody
	public Resp save_CrctBusiScoreItem( 
			String sheet_sch_oid,
			String sheet_cla_oid,
			String student_oid,
			String subject,
			String score_num,
		  HttpServletRequest request) {
		WebResp 	webResp = new WebResp();
	   CrctBusiScoreItemVO crctBusiScoreItemVO=new  CrctBusiScoreItemVO();
	   String  school_oid = SessionManager.getsession(request).getSchool_oid();
	   crctBusiScoreItemVO.setSheet_sch_oid(Long.parseLong(school_oid));
	   crctBusiScoreItemVO.setSheet_cla_oid(Long.parseLong(sheet_cla_oid));
	   crctBusiScoreItemVO.setStudent_oid(Long.parseLong(student_oid));
	
	   crctBusiScoreItemVO.setSubject(subject);
	   crctBusiScoreItemVO.setScore_num(score_num);
	   crctBusiScoreItemVO.setCreate_date(new Date());
	   crctBusiScoreItemService.save(crctBusiScoreItemVO);
		return webResp;
	}
	 //删除
	@RequestMapping("/remove_CrctBusiScoreItem")
	@ResponseBody
	public Resp remove_CrctBusiScoreItem( Long id,
			HttpServletRequest request) {
		WebResp 	webResp = new WebResp();
		CrctBusiScoreItemVO crctBusiScoreItemVO=new  CrctBusiScoreItemVO();
	    crctBusiScoreItemService.remove(id);
		return webResp;
	}
	
//	 //导入成绩
//	@RequestMapping("/daoru_CrctBusiScoreItem")
//	@ResponseBody
//	public Resp daoru_CrctBusiScoreItem( Long id,
//			HttpServletRequest request) {
//		WebResp 	webResp = new WebResp();
////		CrctBusiScoreItemVO crctBusiScoreItemVO=new  CrctBusiScoreItemVO();
////	    crctBusiScoreItemService.remove(id);
//		return webResp;
//	}
	
	

	
	
	

}
